import java.util.Locale;
import java.util.ResourceBundle;

import fr.irstv.controller.FileInfoTextController;
import fr.irstv.controller.MenuBarCloseAppController;
import fr.irstv.controller.MenuBarCloseFileController;
import fr.irstv.controller.MenuBarOpenFileController;
import fr.irstv.controller.MenuBarOpenURLController;
import fr.irstv.dataModel.ImageModel;
import fr.irstv.view.VanishingPointAppView;

public class VanishingPointApp {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		//Manadge locale
		Locale currentLocale = new Locale("en");
		ResourceBundle stringValues = ResourceBundle.getBundle("stringvalues", currentLocale);

		if(args.length !=0){
			if(args.length == 1){
				String language = new String(args[0]);
				currentLocale = new Locale(language);		
				stringValues = ResourceBundle.getBundle("param", currentLocale);
			}else{
				String language = new String(args[0]);
				String country = new String(args[1]);
				currentLocale = new Locale(language, country);		
				stringValues = ResourceBundle.getBundle("param", currentLocale);
			}
		}
		//create the model
		ImageModel imageModel = new ImageModel();
		//create the view
		VanishingPointAppView view = new VanishingPointAppView(stringValues);
		//add Controllers and Listeners
		//JTextField fileInfoText
		FileInfoTextController fileInfoTextController = new FileInfoTextController(view.getFileInfoTextField());
		imageModel.addObserver(fileInfoTextController);
		//Menu Vannishing Point App
		MenuBarCloseAppController menuBarCloseAppController = new MenuBarCloseAppController(view);
		view.getMenuBarView().getVanishingPointAppClose().addActionListener(menuBarCloseAppController);
		//Menu File 
		//open 
		MenuBarOpenFileController menuBarOpenController = new MenuBarOpenFileController(imageModel, view.getMenuBarView().getFileOpen(), view, stringValues);
		view.getMenuBarView().getFileOpen().addActionListener(menuBarOpenController);																																
		imageModel.addObserver(menuBarOpenController);
		//open URL
		MenuBarOpenURLController menuBarOpenURLController = new MenuBarOpenURLController(imageModel, view.getMenuBarView().getURLOpen(), view, stringValues);
		view.getMenuBarView().getURLOpen().addActionListener(menuBarOpenURLController);																																
		imageModel.addObserver(menuBarOpenURLController);
		//close
		MenuBarCloseFileController menuBarCloseController = new MenuBarCloseFileController(imageModel, view.getMenuBarView().getFileClose(), view);
		view.getMenuBarView().getFileClose().addActionListener(menuBarCloseController);																																
		imageModel.addObserver(menuBarCloseController);
	}

}
